﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EssentialWebFramework.Models.Framework
{
    /// <summary>
    /// 设置（用于映射 appsettings.json）
    /// </summary>
    public class GlobalConfig
    {
        /// <summary>
        /// 仅表示业务错误的 http 状态码（设置为 2XX 可以避开前端框架的拦截器）
        /// </summary>
        public const int BUSINESS_ERROR_HTTP_CODE = 222;
        /// <summary>
        /// GlobalConfig 实例
        /// </summary>
        public static GlobalConfig Setting = new GlobalConfig();

        /// <summary>
        /// 数据库连接串
        /// </summary>
        public ConnectionStringsCfg ConnectionStrings { get; set; }

        /// <summary>
        /// JWT 配置
        /// </summary>
        public JWTCfg JWT { get; set; }

        /// <summary>
        /// 公用的 对称加密 密钥
        /// </summary>
        public string CommonUtils_AESSecretKey { get; set; }

        /// <summary>
        /// 管理员的 UserId
        /// </summary>
        public string AdministratorUserId { get; set; }

        /// <summary>
        /// OSS
        /// </summary>
        public OSSCfg OSS { get; set; }

        /// <summary>
        /// 默认的用户角色代码（当用户没有角色时设置）
        /// </summary>
        public string DefaultAppUserRoleCode { get; set; }

        /// <summary>
        /// Mail
        /// </summary>
        public MailCfg Mail { get; set; }

        /// <summary>
        /// 消息队列
        /// </summary>
        public AMQPCfg AMQP { get; set; }

        /// <summary>
        /// 连接串 类
        /// </summary>
        public class ConnectionStringsCfg
        {
            /// <summary>
            /// MySQL 数据库连接
            /// </summary>
            public string MySQL { get; set; }

            /// <summary>
            /// Redis 数据库连接
            /// </summary>
            public string Redis { get; set; }
        }

        /// <summary>
        /// JWT 配置 类
        /// </summary>
        public class JWTCfg
        {
            /// <summary>
            /// 密钥
            /// </summary>
            public string SecurityKey { get; set; }
            /// <summary>
            /// 发布者
            /// </summary>
            public string Issuer { get; set; }
            /// <summary>
            /// 接收者
            /// </summary>
            public string Audience { get; set; }
            /// <summary>
            /// 过期时间（分钟）
            /// </summary>
            public int ExpiresMinutes { get; set; }
            /// <summary>
            /// 刷新密钥 过期时间（分钟）
            /// </summary>
            public TimeSpan RefreshTokenExpireTime { get; set; }
        }

        /// <summary>
        /// OSS
        /// </summary>
        public class OSSCfg
        {
            /// <summary>
            /// 节点
            /// </summary>
            public string EndPoint { get; set; }
            /// <summary>
            /// 密钥 id
            /// </summary>
            public string AccessKeyId { get; set; }
            /// <summary>
            /// 密钥
            /// </summary>
            public string AccessKeySecret { get; set; }
            /// <summary>
            /// OSS 桶名称
            /// </summary>
            public string BucketName { get; set; }
            /// <summary>
            /// 回调地址
            /// </summary>
            public string CallbackUrl { get; set; }
        }

        /// <summary>
        /// 邮件相关配置
        /// </summary>
        public class MailCfg
        {
            /// <summary>
            /// 邮件服务器
            /// </summary>
            public string SMTPServer { get; set; }

            /// <summary>
            /// 密钥
            /// </summary>
            public string SecretKey { get; set; }

            /// <summary>
            /// 源地址（用于描述）
            /// </summary>
            public string FromAddress { get; set; }

            /// <summary>
            /// 展示名称
            /// </summary>
            public string DisplayName { get; set; }
        }

        /// <summary>
        /// 消息队列相关配置
        /// </summary>
        public class AMQPCfg
        {
            /// <summary>
            /// 主机名
            /// </summary>
            public string HostName { get; set; }

            /// <summary>
            /// 端口号
            /// </summary>
            public int Port { get; set; }

            /// <summary>
            /// 用户名
            /// </summary>
            public string UserName { get; set; }

            /// <summary>
            /// 密码
            /// </summary>
            public string Password { get; set; }
            
            /// <summary>
            /// VirtualHost
            /// </summary>
            public string VirtualHost { get; set; }
        }
    }
}
